package com.dkm.orproject.dkmoa.service.serviceimpl;

import com.dkm.orproject.dkmoa.dao.OaCarInsuranceMapper;
import com.dkm.orproject.dkmoa.domain.OaCarInsurance;
import com.dkm.orproject.dkmoa.domain.OaPersonnel;
import com.dkm.orproject.dkmoa.service.OaCarInsuranceService;
import com.dkm.orproject.utils.utils.IdToobtainUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName : OaCarInsuranceServiceImpl  //类名
 * @Description : 车辆违章服务实现类  //描述
 * @Author : 易嵘  //作者
 * @Date: 2021-02-26 10:46  //时间
 */
@Service
public class OaCarInsuranceServiceImpl implements OaCarInsuranceService {

    /**
     * 车辆违章Mapper
     */
    @Resource
    OaCarInsuranceMapper insuranceMapper;

    /**
     * id工具类
     */
    @Resource
    IdToobtainUtils idToobtainUtils;

    @Override
    public List<OaCarInsurance> findAll(String carInsuranceName, String startTime, String endTime, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        return insuranceMapper.findAll(carInsuranceName,startTime,endTime);
    }

    @Override
    public Long rowCount(String carInsuranceName, String startTime, String endTime) {
        return insuranceMapper.rowCount(carInsuranceName,startTime,endTime);
    }

    @Override
    public OaCarInsurance findById(Long id) {
        return insuranceMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(Long id) {
        return insuranceMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteAll(List<Long> list) {
        return insuranceMapper.deleteAll(list);
    }

    @Override
    public List<OaCarInsurance> selectAll(List<Long> list) {
        return insuranceMapper.selectAll(list);
    }

    @Override
    public int add(OaPersonnel personnel, OaCarInsurance car) {
        car.setPkCarInsuranceId(idToobtainUtils.getNumberId());
        car.setCreeatedBy(personnel.getPersonnelName());
        car.setIsRevision("1");
        return insuranceMapper.insertSelective(car);
    }

    @Override
    public int update(OaPersonnel personnel, OaCarInsurance car) {
        car.setUpdatedByu(personnel.getPersonnelName());
        car.setUpdatedTime(new Date());
        return insuranceMapper.updateByPrimaryKeySelective(car);
    }
}
